package main

import (
	"context"
	"fmt"
	"google.golang.org/grpc"
	"mygrpc/message"
	"time"
)

func main(){
	//建立链接
	conn,err := grpc.Dial(":8081",grpc.WithInsecure(),grpc.WithBlock())
	if err!=nil{
		panic(err)
	}
	defer conn.Close()

	ctx,cancel := context.WithTimeout(context.Background(),time.Second * 2)
	defer cancel()

	//创建远程链接客户端
	c := message.NewOrderServerClient(conn)
	req := message.OrderReq{
		OrderId:"002",
		TimeStamp:time.Now().Unix(),
	}
	//调用远程服务器方法
	orderInfo,err := c.GetOrderInfo(ctx,&req)
	if err!=nil{
		fmt.Println(err.Error())
		return
	}
	fmt.Println(orderInfo)
}
